//
//  ZYCTourRecordsListCell.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/26.
//

#import "ZYCTourRecordsListCell.h"
#import "ZYCTourRecordsModel.h"

@interface ZYCTourRecordsListCell  ()

//班级类型
@property (nonatomic, strong) UILabel *titleLabel;
// 授课老师
@property (nonatomic, strong) UILabel *teacherLabel;
// 授课地点
@property (nonatomic, strong) UILabel *addressLabel;

@property (nonatomic, strong) UIButton *statusButton;

@property (nonatomic, strong) UILabel *line;
// 有异议
@property (nonatomic, strong) UILabel *discordLabel;
@end

@implementation ZYCTourRecordsListCell
- (void)setModel:(ZYCTourRecordsModel *)model{
    _model = model;
    _titleLabel.text = model.className;
    _teacherLabel.text = [NSString stringWithFormat:@"授课老师:%@",model.teacherName];
    _addressLabel.text = [NSString stringWithFormat:@"授课地点:%@",model.courseAddress];
    NSInteger status = [model.classStatus integerValue];
    self.discordLabel.hidden = YES;
    if (status == 1) {//正常
        [_statusButton setImage:[UIImage imageNamed:@"zc"] forState:UIControlStateNormal];
    }else if (status == 2) {//迟到
        [_statusButton setImage:[UIImage imageNamed:@"cd"] forState:UIControlStateNormal];
    }else if (status == 3) {//取消
        [_statusButton setImage:[UIImage imageNamed:@"qx"] forState:UIControlStateNormal];
    }else if (status == 4) {//异常
        [_statusButton setImage:[UIImage imageNamed:@"yc"] forState:UIControlStateNormal];
        if ([model.isObjection integerValue] == 1) {
            self.discordLabel.hidden = NO;
        }
    }else{
        [_statusButton setImage:[UIImage imageNamed:@"bj"] forState:UIControlStateNormal];
    }
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.line];
        [self.contentView addSubview:self.teacherLabel];
        [self.contentView addSubview:self.addressLabel];
        [self.contentView addSubview:self.statusButton];
        [self.contentView addSubview:self.discordLabel];
    

        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(20.0f);
            make.top.equalTo(self.contentView).offset(20.0f);
        }];

        [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(20.0f);
            make.right.equalTo(self.contentView).offset(-20.0f);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(17.0f);
            make.height.mas_equalTo(1.0f);
        }];
        

        
        [self.teacherLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(20.0f);
            make.top.equalTo(self.line.mas_bottom).offset(17.5f);
        }];
        
        [self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(20.0f);
            make.top.equalTo(self.teacherLabel.mas_bottom).offset(14.5f);
        }];
        
        [self.statusButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-20.0f);
            make.top.equalTo(self.line.mas_bottom).offset(17.5f);
            make.size.mas_equalTo(CGSizeMake(56.0f, 24.0f));
        }];
        
        [self.discordLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.statusButton);
            make.top.equalTo(self.statusButton.mas_bottom).offset(6.5f);
        }];
        
    }
    return self;
}
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel LabelWithFont:kSystemBoldFont(17.0f) titleColor:HEX_RGB(@"#262A28") textAlignment:ZZTextAlignmentLeft];
    }
    return _titleLabel;
}
- (UILabel *)line {
    if (!_line) {
        _line = [[UILabel alloc] init];
        _line.backgroundColor = HEX_RGB(@"#EAEAEA");
    }
    return _line;
}

- (UILabel *)teacherLabel {
    if (!_teacherLabel) {
        _teacherLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 14.0f) titleColor:HEX_RGB(@"#888888") textAlignment:ZZTextAlignmentLeft];
    }
    return _teacherLabel;
}


- (UILabel *)discordLabel {
    if (!_discordLabel) {
        _discordLabel = [UILabel LabelWithString:@"(有异议)" Font:kCustomFont(@"PingFangSC-Light", 12.0f) titleColor:HEX_RGB(@"#E93C06") textAlignment:ZZTextAlignmentLeft];
        _discordLabel.hidden = YES;
    }
    return _discordLabel;
}

- (UILabel *)addressLabel {
    if (!_addressLabel) {
        _addressLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 14.0f) titleColor:HEX_RGB(@"#888888") textAlignment:ZZTextAlignmentLeft];
    }
    return _addressLabel;
}



- (UIButton *)statusButton {
    if (!_statusButton) {
        _statusButton = [[UIButton alloc] init];
        [_statusButton addTarget:self action:@selector(clickStatusAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _statusButton;
}


- (void)clickStatusAction:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(tourRecordsListCell:)]) {
        [self.delegate tourRecordsListCell:self];
    }
}

@end
